// Copyright 2019-2023 The Inspektor Gadget authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

option go_package = "github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-service/api";

package api;

message GadgetRunRequest {
  // name of the gadget as returned by gadgetDesc.Name()
  string gadgetName = 1;

  // category of the gadget as returned by gadgetDesc.Category()
  string gadgetCategory = 2;

  // params is a combined map of all params a gadget could need (including those
  // of runtime and operators, which need specific prefixes, see implementation in
  // pkg/runtime/grpc)
  map<string, string> params = 3;

  // args are all parameters which were not specified with a flag
  repeated string args = 4;

  // a list of nodes the gadget should run on; if not specified, it should run
  // on all nodes
  repeated string nodes = 10;

  // if set to true, the gadget service should forward the request to each node
  // from the nodes list (or each node it knows, if the list is empty) and combine
  // their output
  bool fanOut = 11;

  // sets the requested log level (see pkg/logger/logger.go)
  uint32 logLevel = 12;

  // time that a gadget should run; use 0, if the gadget should run until it's being
  // stopped or done
  int64 timeout = 13;
}

message GadgetStopRequest {
}

message GadgetEvent {
  // Types are specified in consts.go. Upper 16 bits are used for log severity levels
  uint32 type = 1;
  uint32 seq = 2;
  bytes payload = 3;
}

message GadgetControlRequest {
  oneof Event {
    GadgetRunRequest runRequest = 1;
    GadgetStopRequest stopRequest = 2;
  }
}

message InfoRequest {
  string version = 1;
}

message InfoResponse {
  string version = 1;
  bytes catalog = 2;
  bool experimental = 3;
}

message GetGadgetInfoRequest {
  // params are the gadget's parameters
  map<string, string> params = 1;

  // args are all parameters which were not specified with a flag
  repeated string args = 2;
}

message GetGadgetInfoResponse {
  // This is the GadgetInfo structure defined in pkg/gadgets/run/types/types.go encoded in json.
  // TODO: Ideally we should define the message here, but the implementation is changing too fast.
  // We'll make it once the implementation is more stable.
  bytes info = 1;
}

service GadgetManager {
  rpc GetInfo(InfoRequest) returns (InfoResponse) {}
  rpc GetGadgetInfo(GetGadgetInfoRequest) returns (GetGadgetInfoResponse) {}
  rpc RunGadget(stream GadgetControlRequest) returns (stream GadgetEvent) {}
}
